package top.kaoshanji.p3ch11a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 代码清单-p3ch11a-351页a：使用AtomicInteger类实现的生成唯一标识符的Java类
 * author kaoshanji
 * ^_^
 * create time 2025/2/4 10:50
 */
public class AtomicIdGenerator {

    private static final Logger logger = LogManager.getLogger(AtomicIdGenerator.class);

    private final AtomicInteger counter = new AtomicInteger(0);

    public static void main(String[] args) {
        logger.info("...代码清单-p3ch11a-351页a：使用AtomicInteger类实现的生成唯一标识符的Java类...");

        AtomicIdGenerator generator = new AtomicIdGenerator();

        logger.info("...下一个序号：{}...", generator.getNext());

    }

    public int getNext() {
        return counter.getAndIncrement();
    }



}
